﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace DTS
{
    enum RodzajTransakcji
    {
        sprzedaz = 1,
        kupno = 2,
        krotka_sprzedaz = 3,
        krotkie_kupno = 4
    }
    class Pomocnik
    {
        public static String makeZeros(String input)
        {
            int idx = input.LastIndexOf('.');
            if (idx == -1) return input + ".00";
            if (input.Length - idx == 2) return input + "0";
            return input;
        }
        public static DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            label.Text = promptText;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            textBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text;
            return dialogResult;
        }
        public static String makeOneZeros(String input)
        {
            if (input.Length == 2) return input;
            else
                return "0" + input;
        }
        public static String transakcja(String input)
        {
            if (input.Equals("kupno")) return "Kupno";
            if (input.Equals("krotkie_kupno")) return "Krótkie Kupno";
            if (input.Equals("sprzedaz")) return "Sprzedaż";
            if (input.Equals("krotka_sprzedaz")) return "Krótka Sprzedaż";
            return "olaboga";
        }
        public static Double SMA(List<Double> val)
        {
            return (val.Sum() / (Double)val.Count);
        }
        public static Double EMA(List<Double> val)
        {
            Double licznik=0;
            Double mianownik=0;
            Double alfa = 1 -  2.0 / (Double)(val.Count+1);
            Double actualFactor = 1;
            foreach (var tmp in val)
            {
                licznik += tmp*actualFactor;
                mianownik += actualFactor;
                actualFactor *= alfa;
            }
            return licznik / mianownik;
            
        }
    }
    struct SelectedCell
    {
        public int row;
        public int column;
        public SelectedCell(int _row, int _column)
        {
            row = _row;
            column = _column;
        }
    }
}
